home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 262 / SOMC Family Forum 262.iso / Xtras / Animation Wizard.dir / 00010_Credits.ls < prev    next >
Encoding:
Text File  |  1997-05-10  |  14.7 KB  |  374 lines

  1. property ioFieldList, iFieldFocus, ioFIeldFocus, iCurrentMotionStyleIndex, iCurrentVisualStyleIndex, ikMotionScrollingUp, ikMotionIndividual, iFirstTime, iSaveSeconds, iSaveFPS, iSaveDelayEnter, iSaveDelayHold, iSaveMark, iSaveCycles
  2.  
  3. on birth me
  4.   global goCreditsText, goSeconds, goFPS, goDelayEnter, goDelayHold
  5.   set ioFieldList to [goCreditsText, goSeconds, goFPS, goDelayEnter, goDelayHold]
  6.   set ikMotionScrollingUp to 1
  7.   set ikMotionIndividual to 2
  8.   set iCurrentMotionStyleIndex to ikMotionScrollingUp
  9.   set iCurrentVisualStyleIndex to 1
  10.   set iFieldFocus to 1
  11.   set iFirstTime to 1
  12.   return me
  13. end
  14.  
  15. on mInit me
  16.   global goSeconds, goFPS, goDelayEnter, goDelayHold, goCredits, goMarkFrame, goVisualStyles, goMotionStyles, goScoreMgr, goAnimateTitle
  17.   mInit(goMarkFrame, 4)
  18.   if iFirstTime then
  19.     mSetValue(goSeconds, 5)
  20.     mSetValue(goFPS, 5)
  21.     mSetValue(goDelayEnter, 5)
  22.     mSetValue(goDelayHold, 0)
  23.     mSetValue(goMarkFrame, 1)
  24.     set iFirstTime to 0
  25.   else
  26.     mSetValue(goSeconds, iSaveSeconds)
  27.     mSetValue(goFPS, iSaveFPS)
  28.     mSetValue(goDelayEnter, iSaveDelayEnter)
  29.     mSetValue(goDelayHold, iSaveDelayHold)
  30.     mSetValue(goMarkFrame, iSaveMark)
  31.   end if
  32.   set ioFIeldFocus to getAt(ioFieldList, iFieldFocus)
  33.   set goMotionStyles to 0
  34.   set goMotionStyles to birth(script "RadioButton", 26, 2, 0, iCurrentMotionStyleIndex)
  35.   if the machineType < 256 then
  36.     mInit(goVisualStyles, the number of member "CreditsVisualStylesMac", iCurrentVisualStyleIndex, 8, 19)
  37.   else
  38.     mInit(goVisualStyles, the number of member "CreditsVisualStylesPC", iCurrentVisualStyleIndex, 8, 19)
  39.   end if
  40.   set the keyDownScript to "mCheckKey(goCredits)"
  41. end
  42.  
  43. on mSetFieldFocus me, oWhom
  44.   set where to getOne(ioFieldList, oWhom)
  45.   if where = 0 then
  46.     alert("Internal error - mSetFieldFocus could not find object")
  47.     return 
  48.   end if
  49.   set iFieldFocus to where
  50.   set ioFIeldFocus to getAt(ioFieldList, iFieldFocus)
  51. end
  52.  
  53. on mCheckKey me
  54.   if the key = TAB then
  55.     set iFieldFocus to IncrMod(iFieldFocus, count(ioFieldList))
  56.     set ioFIeldFocus to getAt(ioFieldList, iFieldFocus)
  57.     pass()
  58.   else
  59.     if iFieldFocus = 1 then
  60.       pass()
  61.     else
  62.       if (offset(the key, "0123456789") > 0) or (the key = BACKSPACE) then
  63.         pass()
  64.       else
  65.         dontPassEvent()
  66.       end if
  67.     end if
  68.   end if
  69. end
  70.  
  71. on mSetNewMotionStyle me, theNewStyleIndex
  72.   set iCurrentMotionStyleIndex to theNewStyleIndex
  73. end
  74.  
  75. on mSetNewVisualStyle me, theNewStyleIndex
  76.   set iCurrentVisualStyleIndex to theNewStyleIndex
  77. end
  78.  
  79. on mValidate me
  80.   set lastFieldOKFlag to mValidate(ioFIeldFocus)
  81.   return lastFieldOKFlag
  82. end
  83.  
  84. on mCheckFormat me
  85.   set theText to field "CreditsText"
  86.   set nLines to the number of lines in theText
  87.   repeat with thisLine = 1 to nLines
  88.     if offset(":", line thisLine of field "CreditsText") = 0 then
  89.       alert("Line" && thisLine && "of the Credits text does not contain a colon.")
  90.       return 0
  91.     end if
  92.   end repeat
  93.   return 1
  94. end
  95.  
  96. on mParseLine me, theLineToParse, theHeaderFont, theHeaderSize, theBodyFont, theBodySize
  97.   global gCastNumTextAsBitmap
  98.   set where to offset(":", theLineToParse)
  99.   set theHeaderText to char 1 to where of theLineToParse
  100.   set nChars to the number of chars in theLineToParse
  101.   set theBodyText to char where + 1 to nChars of theLineToParse
  102.   set castNumHeader to mModifyRichTextCM(goCastMgr, theHeaderText, theHeaderFont, theHeaderSize)
  103.   if castNumHeader = 0 then
  104.     return 0
  105.   end if
  106.   set the picture of member gCastNumTextAsBitmap to the picture of member castNumHeader
  107.   set widthHeader to the width of member gCastNumTextAsBitmap
  108.   set heightHeader to the height of member castNumHeader / the number of lines in the text of member castNumHeader
  109.   set castNumHeaderTarget to mFindFreeCastRun(goCastMgr, 1, 1)
  110.   copyToClipBoard(member castNumHeader)
  111.   tell the stage
  112.     pasteClipBoardInto(member castNumHeaderTarget)
  113.     set the name of member castNumHeaderTarget to "RichText" && string(the ticks)
  114.   end tell
  115.   set castNumBody to mModifyRichTextCM(goCastMgr, theBodyText, theBodyFont, theBodySize)
  116.   if castNumBody = 0 then
  117.     return 0
  118.   end if
  119.   set the picture of member gCastNumTextAsBitmap to the picture of member castNumBody
  120.   set widthBody to the width of member gCastNumTextAsBitmap
  121.   set heightBody to the height of member castNumBody / the number of lines in the text of member castNumBody
  122.   set castNumBodyTarget to mFindFreeCastRun(goCastMgr, 1, 1)
  123.   copyToClipBoard(member castNumBody)
  124.   tell the stage
  125.     pasteClipBoardInto(member castNumBodyTarget)
  126.     set the name of member castNumBodyTarget to "RichText" && string(the ticks)
  127.   end tell
  128.   return [castNumHeaderTarget, castNumBodyTarget, widthHeader, heightHeader, widthBody, heightBody]
  129. end
  130.  
  131. on mSplitAndCreate2 me, theTextToParse, theHeaderFont, theHeaderSize, theBodyFont, theBodySize
  132.   global gCastNumTextAsBitmap
  133.   set nLines to the number of lines in theTextToParse
  134.   set theHeaderText to EMPTY
  135.   set theBodyText to EMPTY
  136.   repeat with thisLine = 1 to nLines
  137.     set theLineToParse to line thisLine of theTextToParse
  138.     set where to offset(":", theLineToParse)
  139.     set theHeaderPart to char 1 to where of theLineToParse
  140.     set nChars to the number of chars in theLineToParse
  141.     set theBodyPart to char where + 1 to nChars of theLineToParse
  142.     if thisLine > 1 then
  143.       set theHeaderText to theHeaderText & RETURN
  144.       set theBodyText to theBodyText & RETURN
  145.     end if
  146.     set theHeaderText to theHeaderText & theHeaderPart
  147.     set theBodyText to theBodyText & theBodyPart
  148.   end repeat
  149.   set castNumHeader to mModifyRichTextCM(goCastMgr, theHeaderText, theHeaderFont, theHeaderSize)
  150.   if castNumHeader = 0 then
  151.     return 0
  152.   end if
  153.   set the picture of member gCastNumTextAsBitmap to the picture of member castNumHeader
  154.   set widthHeader to the width of member gCastNumTextAsBitmap
  155.   set heightHeader to the height of member castNumHeader
  156.   set castNumHeaderTarget to mFindFreeCastRun(goCastMgr, 1, 1)
  157.   copyToClipBoard(member castNumHeader)
  158.   tell the stage
  159.     pasteClipBoardInto(member castNumHeaderTarget)
  160.     set the name of member castNumHeaderTarget to "RichText" && string(the ticks)
  161.   end tell
  162.   set castNumBody to mModifyRichTextCM(goCastMgr, theBodyText, theBodyFont, theBodySize)
  163.   if castNumBody = 0 then
  164.     return 0
  165.   end if
  166.   set the picture of member gCastNumTextAsBitmap to the picture of member castNumBody
  167.   set widthBody to the width of member gCastNumTextAsBitmap
  168.   set heightBody to the height of member castNumBody
  169.   set castNumBodyTarget to mFindFreeCastRun(goCastMgr, 1, 1)
  170.   copyToClipBoard(member castNumBody)
  171.   tell the stage
  172.     pasteClipBoardInto(member castNumBodyTarget)
  173.     set the name of member castNumBodyTarget to "RichText" && string(the ticks)
  174.   end tell
  175.   return [castNumHeaderTarget, castNumBodyTarget, widthHeader, heightHeader, widthBody, heightBody]
  176. end
  177.  
  178. on mCreate me
  179.   global goMarkFrame, goMotionStyles, goVisualStyles, goScoreMgr, goCastMgr, gDevelopmentFlag, gCastNumTextAsBitmap, goPlatform
  180.   if not mValidate(me) then
  181.     return 
  182.   end if
  183.   if the last char in field "CreditsText" = RETURN then
  184.     delete char -30000 of field "CreditsText"
  185.   end if
  186.   if field "CreditsText" = EMPTY then
  187.     alert("Please enter some text for the Credit.")
  188.     return 
  189.   end if
  190.   if not mCheckFormat(me) then
  191.     return 
  192.   end if
  193.   tell the stage
  194.     set theStageFrame to the frame
  195.   end tell
  196.   set castNumVisualStyle to mGetCastNum(goVisualStyles, iCurrentVisualStyleIndex)
  197.   set theVisualStyleName to the name of cast castNumVisualStyle
  198.   set theHeaderFont to word 2 of theVisualStyleName
  199.   set theHeaderSize to word 3 of theVisualStyleName
  200.   set theBodyFont to word 4 of theVisualStyleName
  201.   set theBodySize to word 5 of theVisualStyleName
  202.   set theSeconds to integer(field "Seconds")
  203.   set fps to integer(field "FPS")
  204.   set nFrames to integer(theSeconds * fps)
  205.   set delayEnter to integer(field "DelayEnter")
  206.   set delayHold to integer(field "DelayHold")
  207.   set markFirst to mGetValue(goMarkFrame)
  208.   set theForeColor to 255
  209.   set theBackColor to 0
  210.   if iCurrentMotionStyleIndex = ikMotionScrollingUp then
  211.     set thisList to mSplitAndCreate2(me, field "CreditsText", theHeaderFont, theHeaderSize, theBodyFont, theBodySize)
  212.     if thisList = 0 then
  213.       return 
  214.     end if
  215.     set castNumHeader to getAt(thisList, 1)
  216.     set castNumBody to getAt(thisList, 2)
  217.     set theWidthHeader to getAt(thisList, 3)
  218.     set theHeightHeader to getAt(thisList, 4)
  219.     set theWidthBody to getAt(thisList, 5)
  220.     set theHeightBody to getAt(thisList, 6)
  221.     if delayEnter > 0 then
  222.       set nTotalFrames to nFrames + 1
  223.     else
  224.       set nTotalFrames to nFrames
  225.     end if
  226.     if not mInit(goScoreMgr, nTotalFrames, 2) then
  227.       return 
  228.     end if
  229.     set chHeader to mGetNextSelectedChannel(goScoreMgr)
  230.     set chBody to mGetNextSelectedChannel(goScoreMgr)
  231.     set theFrameNum to mGetStartFrame(goScoreMgr)
  232.     set frameList to []
  233.     repeat with i = theFrameNum to theFrameNum + nTotalFrames - 1
  234.       add(frameList, [i])
  235.     end repeat
  236.     if markFirst then
  237.       set theLabel to "AW.Credit." & word 1 of the text of field "CreditsText" & " " & mGetGeneratedScoreSelection(goScoreMgr)
  238.       set firstFrame to getAt(frameList, 1)
  239.       add(firstFrame, [#label, theLabel])
  240.       setAt(frameList, 1, firstFrame)
  241.     end if
  242.     set relFrameCount to 1
  243.     set firstFrame to getAt(frameList, relFrameCount)
  244.     set secondFrame to getAt(frameList, relFrameCount + 1)
  245.     if delayEnter > 0 then
  246.       add(firstFrame, [#tempo, -delayEnter])
  247.       add(secondFrame, [#tempo, fps])
  248.       setAt(frameList, relFrameCount, firstFrame)
  249.       setAt(frameList, relFrameCount + 1, secondFrame)
  250.       set theFrameNum to theFrameNum + 1
  251.       set relFrameCount to relFrameCount + 1
  252.     else
  253.       add(firstFrame, [#tempo, fps])
  254.       add(secondFrame, [#tempo, 0])
  255.       setAt(frameList, relFrameCount, firstFrame)
  256.       setAt(frameList, relFrameCount + 1, secondFrame)
  257.     end if
  258.     set theStageWidth to mGetStageWidth(goScoreMgr)
  259.     set theStageHeight to mGetStageHeight(goScoreMgr)
  260.     set totalTextWidth to theWidthHeader + theWidthBody
  261.     set xLocHeader to integer((theStageWidth / 2) - (totalTextWidth / 2))
  262.     set xLocBody to integer(xLocHeader + theWidthHeader)
  263.     set maxHeight to max(theHeightHeader, theHeightBody)
  264.     set yStart to theStageHeight - 10
  265.     set yEnd to 0 - maxHeight - 10
  266.     set yInc to float(yEnd - yStart) / float(nFrames)
  267.     set yLoc to yStart
  268.     repeat with thisFrame = 1 to nFrames
  269.       set currentFrame to getAt(frameList, relFrameCount)
  270.       add(currentFrame, [#sprite, chHeader, castNumHeader, theForeColor, theBackColor, xLocHeader, yLoc, 0, 0])
  271.       add(currentFrame, [#sprite, chBody, castNumBody, theForeColor, theBackColor, xLocBody, yLoc, 0, 0])
  272.       setAt(frameList, relFrameCount, currentFrame)
  273.       set theFrameNum to theFrameNum + 1
  274.       set relFrameCount to relFrameCount + 1
  275.       set yLoc to integer(yLoc + yInc)
  276.     end repeat
  277.   else
  278.     set nSourceLines to the number of lines in field "CreditsText"
  279.     set nFrames to (delayEnter + 1) * nSourceLines
  280.     if not mInit(goScoreMgr, nFrames, 2) then
  281.       return 
  282.     end if
  283.     set maxHeaderWidth to 0
  284.     set maxBodyWidth to 0
  285.     set castNumList to []
  286.     repeat with thisLine = 1 to nSourceLines
  287.       set thisList to mParseLine(me, line thisLine of field "CreditsText", theHeaderFont, theHeaderSize, theBodyFont, theBodySize)
  288.       if thisList = 0 then
  289.         return 
  290.       end if
  291.       set thisCastNumHeaderTarget to getAt(thisList, 1)
  292.       set thisCastNumBodyTarget to getAt(thisList, 2)
  293.       set thisWidthHeader to getAt(thisList, 3)
  294.       set thisHeightHeader to getAt(thisList, 4)
  295.       set thisWidthBody to getAt(thisList, 5)
  296.       set thisHeightBody to getAt(thisList, 6)
  297.       if thisWidthHeader > maxHeaderWidth then
  298.         set maxHeaderWidth to thisWidthHeader
  299.       end if
  300.       if thisWidthBody > maxBodyWidth then
  301.         set maxBodyWidth to thisWidthBody
  302.       end if
  303.       add(castNumList, [thisCastNumHeaderTarget, thisCastNumBodyTarget])
  304.     end repeat
  305.     set theForeColor to 255
  306.     set theBackColor to 0
  307.     set chHeader to mGetNextSelectedChannel(goScoreMgr)
  308.     set chBody to mGetNextSelectedChannel(goScoreMgr)
  309.     set theFrameNum to mGetStartFrame(goScoreMgr)
  310.     set frameList to []
  311.     repeat with i = theFrameNum to theFrameNum + nFrames - 1
  312.       add(frameList, [i])
  313.     end repeat
  314.     if markFirst then
  315.       set theLabel to "AW.Credit." & word 1 of the text of field "CreditsText" & " " & mGetGeneratedScoreSelection(goScoreMgr)
  316.       set firstFrame to getAt(frameList, 1)
  317.       add(firstFrame, [#label, theLabel])
  318.       setAt(frameList, 1, firstFrame)
  319.     end if
  320.     set relFrameCount to 1
  321.     set theStageWidth to mGetStageWidth(goScoreMgr)
  322.     set theStageHeight to mGetStageHeight(goScoreMgr)
  323.     set totalTextWidth to maxHeaderWidth + maxBodyWidth
  324.     set xLocHeader to integer((theStageWidth / 2) - (totalTextWidth / 2))
  325.     set xLocBody to integer(xLocHeader + maxHeaderWidth)
  326.     set yLoc to integer(theStageHeight / 2)
  327.     repeat with thisLine = 1 to nSourceLines
  328.       set currentFrame to getAt(frameList, relFrameCount)
  329.       add(currentFrame, [#tempo, fps])
  330.       setAt(frameList, relFrameCount, currentFrame)
  331.       set thisCastNumList to getAt(castNumList, thisLine)
  332.       set castNumHeader to getAt(thisCastNumList, 1)
  333.       set castNumBody to getAt(thisCastNumList, 2)
  334.       repeat with thisFrame = 1 to delayEnter
  335.         set currentFrame to getAt(frameList, relFrameCount)
  336.         add(currentFrame, [#sprite, chHeader, castNumHeader, theForeColor, theBackColor, xLocHeader, yLoc, 0, 0])
  337.         add(currentFrame, [#sprite, chBody, castNumBody, theForeColor, theBackColor, xLocBody, yLoc, 0, 0])
  338.         setAt(frameList, relFrameCount, currentFrame)
  339.         set theFrameNum to theFrameNum + 1
  340.         set relFrameCount to relFrameCount + 1
  341.       end repeat
  342.       if delayHold > 0 then
  343.         set currentFrame to getAt(frameList, relFrameCount)
  344.         add(currentFrame, [#tempo, delayHold])
  345.         add(currentFrame, [#sprite, chHeader, castNumHeader, theForeColor, theBackColor, xLocHeader, yLoc, 0, 0])
  346.         add(currentFrame, [#sprite, chBody, castNumBody, theForeColor, theBackColor, xLocBody, yLoc, 0, 0])
  347.         setAt(frameList, relFrameCount, currentFrame)
  348.         set relFrameCount to relFrameCount + 1
  349.         set theFrameNum to theFrameNum + 1
  350.       end if
  351.     end repeat
  352.   end if
  353.   mWriteFrame(goScoreMgr, frameList)
  354.   set labelName to "Credits" & goPlatform
  355.   go(label(labelName) + 2)
  356.   if not gDevelopmentFlag then
  357.     tell the stage
  358.       go(theStageFrame)
  359.     end tell
  360.   end if
  361.   mClean(goScoreMgr)
  362. end
  363.  
  364. on mCleanUp me
  365.   global goMotionStyles, goSeconds, goFPS, goDelayEnter, goDelayHold, goMarkFrame
  366.   mCleanUp(goMotionStyles)
  367.   set iSaveSeconds to mGetValue(goSeconds)
  368.   set iSaveFPS to mGetValue(goFPS)
  369.   set iSaveDelayEnter to mGetValue(goDelayEnter)
  370.   set iSaveDelayHold to mGetValue(goDelayHold)
  371.   set iSaveMark to mGetValue(goMarkFrame)
  372.   mCleanUp(goMarkFrame)
  373. end
  374.